package com.yn.xgame.game;

import com.google.common.collect.ImmutableMap;
import com.yn.xgame.game.message.PlayerLeave;

import java.util.HashMap;
import java.util.Map;

/**
 * 房间管理
 * Created by wangboo on 17/7/15.
 */
public abstract class RoomManager {

    public static final Integer TYPE_BIG_ROOM = 0;
    public static final Integer TYPE_AUTO_MATCH = 1;

    public static final Map<String, Integer> type_map = ImmutableMap.of(
            "big-room", TYPE_BIG_ROOM,
            "auto-match", TYPE_AUTO_MATCH
    );

    // uid - player
    private Map<Integer, RoomPlayer> roomUserPlayerMap = new HashMap<>();

    protected int gameserverid;
    protected int goldPoint;         // 金币最低下限检查
    protected int id;
    protected int minStartSize;
    protected int type;
    protected int tableSize;         // 每张桌子，可以坐多少人
    protected String showName;

    RoomManager(int id, int gameserverid, int tableSize,
                int goldPoint, int minStartSize, int type) {
        this.id = id;
        this.gameserverid = gameserverid;
        this.tableSize = tableSize;
        this.goldPoint = goldPoint;
        this.minStartSize = minStartSize;
        this.type = type;
    }

    public int getId() {
        return id;
    }

    public int getUserCount() {
        return roomUserPlayerMap.size();
    }


    public boolean hasGoldCheckPoint() {
        return goldPoint > 0;
    }

    public int getGoldPoint() {
        return goldPoint;
    }

    public String getShowName() {
        return showName;
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }

    public int getMinStartSize() {
        return minStartSize;
    }

    public void setMinStartSize(int minStartSize) {
        this.minStartSize = minStartSize;
    }

    public abstract GCRoomTable handlePlayerJoin(RoomPlayer player);

    public abstract void handlePlayerLeave(PlayerLeave leave);

    public abstract int getMaxUserCount();

    public abstract boolean isFull();

    public int getGameServerId() {
        return gameserverid;
    }

    public abstract GCRoomTable getTable(String tableId);

}
